package org.csc.api.feign;

import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;

@FeignClient(name = "${service.api}", fallbackFactory = FeignClientFallbackFactory.class, decode404 = true)
public interface ApiService {

    String TEST = "public/test";

    @RequestMapping(TEST)
    String apiTest();

}


@Component
class FeignClientFallbackFactory implements FallbackFactory<ApiService> {
    private static final Logger log = LoggerFactory.getLogger(FeignClientFallbackFactory.class);
    @Override
    public ApiService create(Throwable throwable) {
        return new ApiService() {
            @Override
            public String apiTest() {
                log.info("服务异常 -------> {}", throwable.getMessage());
                return "服务异常";
            }
        };
    }
}

